$(function () {
 
    //绑定父级类型
    bindFatherType();
    //绑定折扣专区
    bindDisShop(102,0);
    //绑定近期热门
    bindHotShop(102,0)
    //绑定歌剧
    bindGeJu(102,0,2);//首页加载是默认状态为0，也就是显示6条
    //绑定儿童亲子
    bindChild(102,0,6);//首页加载是默认状态为0，也就是显示6条

    //点击类别上按钮
    $("#banner-one").on('click','.typeId',function () {
       //获取当前类型Id
        var id=this.id;
        //跳转页面，将类型Id参数
        location.href="http://localhost:8080/static/html2/action.html?id="+id;
    });

    /*点击折扣的更多按钮时*//*-------------------------------------------------------------方法暂定*/
    $("#moreDis").click(function () {
        /*正常这里应该传入城市Id*/

        //应该应该先跳转页面
        //然后在查询数据绑定
        /* bindDisShop(102,1);*/
    });

    //点击儿童亲子，话剧歌剧更多按钮时
    $(".more").click(function () {
        //获取类别id
        var id=this.id;
        //跳转页面，将类型Id参数
        location.href="http://localhost:8080/static/html2/action.html?id="+id;

    });

});

//绑定父级类型
function bindFatherType() {
    $.ajax({
        type: "Get",
        url: "http://cn.pn.com/api-pn/item/type/p/listAll",
        dataType: "json",
        success: function(data){

            var fType=$("#banner-one ul");
            $.each(data,function (i,e) {
                var $li="<li><div></div><a href=\"javascript:;\" id='"+e.showTypeId+"' class='typeId'>"+e.typeName+"</a><img src=\"../img/1.png\" class=\"img\"></li>";
                fType.append($li);

            });
        },
        error: function(msg){
            alert( "网络连接异常！！！");
        }
    });
}

//绑定折扣商品
function bindDisShop(cityId,statusId) {
    $.ajax({
        type: "Post",
        url: "http://cn.pn.com/api-pn/item/dis/p/getDisCommodityListByCityId",
        data:{cityId:cityId,statusId:statusId},
        dataType: "json",
        success: function(data){

            var $ul=$("#disShop");
            $.each(data,function (i,e) {
                $.each(e.skuList,function (index,e2) {

                    var $li="<li><img src=\"../img/7.jpg\"><span>"+e2.discount+"<br><b>折</b></span><a href=\"javascript:;\">["+e.cityName+"] "+e.commodityName+"</a><p><i>￥</i>"+e2.disPrice+"<b>￥"+e2.price+"</b></p></li>";
                    $ul.append($li);
                });
            });
        },
        error: function(msg){
            alert( "网络连接异常！！！");
        }
    });
}

//绑定热门商品
function bindHotShop(cityId,statusId){
    $.ajax({
        type: "Post",
        url: "http://cn.pn.com/api-pn/item/dis/p/getHotCommodityListByCityId",
        data:{cityId:cityId,statusId:statusId},
        dataType: "json",
        success: function(data){

            var $ul=$("#hotShop");
            $.each(data,function (i,e) {
                $.each(e.skuList,function (index,e2) {
                    var $li="<li><img src=\"../img/1.jpg\"><span><b>"+e2.shopCount+"</b><br>🔥想看</span><a href=\"javascript:;\">["+e.cityName+"]"+e.commodityName+" </a><p><i>￥</i>"+e2.disPrice+"<b> 起</b></p></li>";
                    $ul.append($li);
                });
            });
        },
        error: function(msg){
            alert( "网络连接异常！！！");
        }
    });
}


/*绑定歌剧*/
function bindGeJu(cityId,statusId,fatherTypeId){
    $.ajax({
        type: "Post",
        url: "http://cn.pn.com/api-pn/item/dis/p/getCommodityMapByFatherList",
        data:{cityId:cityId,statusId:statusId,fatherTypeId:fatherTypeId},
        dataType: "json",
        success: function(data){
            var $bindGeJu=$("#bindGeJu");
            $.each(data,function (i,e){
                    $.each(e.skuList,function (index,e2) {
                        var $li="<li><img src=\"../img/xiao.jpg\"><p>["+e.cityName+"]"+e.commodityName+"<br><i>¥</i> <b>"+e2.disPrice+"</b> <em>起</em></p></li>";
                        $bindGeJu.append($li);
                    })
            })
        },
        error: function(msg){
            alert( "网络连接异常！！！");
        }
    });
}

/*绑定儿童亲子*/
function bindChild(cityId,statusId,fatherTypeId){
    $.ajax({
        type: "Post",
        url: "http://cn.pn.com/api-pn/item/dis/p/getCommodityMapByFatherList",
        data:{cityId:cityId,statusId:statusId,fatherTypeId:fatherTypeId},
        dataType: "json",
        success: function(data){
            var $bindChild=$("#bindChild");
            $.each(data,function (i,e){
                $.each(e.skuList,function (index,e2) {
                    var $li="<li><img src=\"../img/xiao1.jpg\"><p>["+e.cityName+"]"+e.commodityName+"<br><i>¥</i> <b>"+e2.disPrice+"</b> <em>起</em></p></li>";
                    $bindChild.append($li);
                })
            })
        },
        error: function(msg){
            alert( "网络连接异常！！！");
        }
    });
}
